package main

import (
	"encoding/json"
	"fmt"
	"github.com/nsqio/go-nsq"
	"go-web/model"
	"log"
	"time"
)

func main() {

	conn := "39.100.58.10:4150"
	config := nsq.NewConfig()

	q, _ := nsq.NewConsumer("order", "stock", config)
	q.AddHandler(nsq.HandlerFunc(func(message *nsq.Message) error {

		log.Printf("Got a message: %s %s", message.ID, message.Body)

		var orderMsg model.OrderMsg
		json.Unmarshal(message.Body, &orderMsg)
		fmt.Println(orderMsg)

		return nil
	}))
	err := q.ConnectToNSQD(conn)
	if err != nil {
		log.Panic(err)
	}

	time.Sleep(100 * time.Second)
}
